/**
 * PanelResponsables.java
 */

 /**
 *  AdSec: Administrador de Secundarias
 *  Copyright (C) 2009 Daniela Ramírez Chaves (dannyrch@gmail.com)
 *  Copyright (C) 2009 Leonel Salazar Valverde (leo87sv@gmail.com)
 *
 *  This file is part of AdSec.
 *  AdSec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AdSec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AdSec.  If not, see <http://www.gnu.org/licenses/>.
 */

package adsec.presentacion;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Calendar;
import java.sql.Date;
import java.util.Iterator;
import java.util.LinkedList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.MaskFormatter;
import adsec.entidades.Estado;
import adsec.entidades.Estudiante;
import adsec.entidades.Permiso;
import adsec.entidades.Responsable;
import adsec.negocios.AdministradorSeguridad;
import adsec.negocios.ControladoraEstudiante;
import adsec.negocios.ControladoraResponsable;
import adsec.negocios.UtilidadesCapaNegocios;
import org.jdesktop.application.Action;


public class PanelResponsables extends JPanel implements ListSelectionListener, ItemListener{

    private AdministradorSeguridad adminSeguridad;
    private ControladoraResponsable controladoraResponsable;
    private Permiso permisoResponsable;
    private Estado estado;
    /** Creates new form PanelEstudiantes */
    public PanelResponsables() {
        initComponents();
        //this.iniciarPanelResponsable();
    }

    protected MaskFormatter createFormatter(String s) {
        MaskFormatter formatter = null;
        try {
            formatter = new MaskFormatter(s);
        } catch (java.text.ParseException exc) {
            System.err.println("formatter is bad: " + exc.getMessage());
            System.exit(-1);
        }
        return formatter;
    }

    public void itemStateChanged(ItemEvent evento){
        JComboBox fuente = (JComboBox) evento.getSource();
        if(evento.getStateChange() == ItemEvent.SELECTED){
            if(fuente == this.cbCedula){             
                this.cbNombreApellidos.removeItemListener(this);
                this.cbNombreApellidos.setSelectedIndex(this.cbCedula.getSelectedIndex());
                this.cbNombreApellidos.addItemListener(this);
                this.cargarGridResponsables();
            }else{
                if(fuente == this.cbNombreApellidos){                  
                    this.cbCedula.removeItemListener(this);
                    this.cbCedula.setSelectedIndex(this.cbNombreApellidos.getSelectedIndex());
                    this.cbCedula.addItemListener(this);
                    this.cargarGridResponsables();
                }
            }
        }
    }//fin de itemStateChanged

    public void iniciarPanelResponsable(){
        this.adminSeguridad = AdministradorSeguridad.getInstancia();
        this.controladoraResponsable = new ControladoraResponsable();
        this.permisoResponsable = this.adminSeguridad.getPermiso(UtilidadesCapaNegocios.moduloResponsables);
        this.estado = new Estado();
        this.setHabilitarCampos(false);
        this.habilitarBotonesIME(this.permisoResponsable.isInsertar(), false, false);
        this.cargarComboBoxDatosEstudiante();
        this.habilitarAceptarCancelar(false);
    }//fin de iniciarPanelResponsables
    /**
     ** Recibe un boolean para habilitar todos los campos de la pantalla
     ** o ya sea deshabilitarlos
     **/
    private void setHabilitarCampos(boolean habilitar){
        this.txtNombre.setEnabled(habilitar);
        this.txtApellidos.setEnabled(habilitar);
        this.txtCedula.setEditable(habilitar);
        this.spinDia.setEnabled(habilitar);
        this.spinMes.setEnabled(habilitar);
        this.spinAño.setEnabled(habilitar);
        this.cbSexo.setEnabled(habilitar);
        this.txtNacionalidad.setEditable(habilitar);
        this.txtTelefono1.setEditable(habilitar);
        this.txtTelefono2.setEditable(habilitar);
        this.txtProvincia.setEditable(habilitar);
        this.txtCanton.setEditable(habilitar);
        this.txtDistrito.setEditable(habilitar);
        this.txtOtrasSeñas.setEditable(habilitar);
    }//fin de setHabilitarCampos

    /**
     ** Habilita o deshabilita los botones insertar, modificar y eliminar
     **/
    private void habilitarBotonesIME(boolean insertar, boolean modificar, boolean eliminar){
        this.btnInsertar.setEnabled(insertar);
        this.btnModificar.setEnabled(modificar);
        this.btnEliminar.setEnabled(eliminar);
    }

    /**
     ** Habilita o deshabilita los botones aceptar y cancelar
     **/
    private void habilitarAceptarCancelar(boolean habilitar){
        this.btnAceptar.setEnabled(habilitar);
        this.btnCancelar.setEnabled(habilitar);
    }

    /**
     ** Limpia todos los campos de la pantalla
     **/
    private void limpiarCampos(){
        this.txtNombre.setText("");
        this.txtApellidos.setText("");
        this.txtCedula.setText("0-0000-0000");
        this.spinDia.getModel().setValue(1);
        this.spinMes.getModel().setValue(1);
        this.spinAño.getModel().setValue(1950);
        this.cbSexo.setSelectedIndex(0);
        this.txtNacionalidad.setText("");
        this.txtTelefono1.setText("00-00-00-00");
        this.txtTelefono2.setText("00-00-00-00");
        this.txtProvincia.setText("");
        this.txtCanton.setText("");
        this.txtDistrito.setText("");
        this.txtOtrasSeñas.setText("");
    }//fin de limpiarCampos


    /**
     ** Obtiene todos los datos del responsable y crea un objeto de tipo Responsable
     ** el cual es retornado
     ** @return Un Responsable
     */
    public Responsable obtenerDatosResponsable(){
        Responsable responsable = new Responsable();
        responsable.setCedula(this.txtCedula.getText());
        responsable.setNombre(this.txtNombre.getText());
        responsable.setApellidos(this.txtApellidos.getText());
        responsable.setFechaNac(obtenerFecha());
        responsable.setSexo(this.cbSexo.getSelectedItem().toString().substring(0, 1));
        responsable.setTelefono1(this.txtTelefono1.getText());
        responsable.setTelefono2(this.txtTelefono2.getText());
        responsable.setNacionalidad(this.txtNacionalidad.getText());
        responsable.setProvincia(this.txtProvincia.getText());
        responsable.setCanton(this.txtCanton.getText());
        responsable.setDistrito(this.txtDistrito.getText());
        responsable.setOtrasSenias(this.txtOtrasSeñas.getText());
        return responsable;
    }//fin de obtenerDatosResponsable
    
    private Date obtenerFecha(){
        int dia = Integer.parseInt(this.spinDia.getValue().toString());
        int mes = Integer.parseInt(this.spinMes.getValue().toString())-1;
        int año = Integer.parseInt(this.spinAño.getValue().toString());
        Calendar calendario = Calendar.getInstance();
        calendario.clear();
        calendario.set(año,mes,dia);
        Date fecha = new Date(calendario.getTimeInMillis());
        return fecha;
    }//fin de obtenerFecha


    private void insertarResponsable(){
        Responsable responsable = this.obtenerDatosResponsable();
        String cedulaEstudiante = cbCedula.getSelectedItem().toString();
        System.out.println("Cedula Estudiante: " + cedulaEstudiante);
        if(!UtilidadesCapaNegocios.existeLlave(Responsable.nombreTabla, Responsable.cedulaNC, responsable.getCedula())){
            int resultado = this.controladoraResponsable.insertarResponsable(responsable, cedulaEstudiante);
            if(resultado == UtilidadesCapaNegocios.QUERY_OK){
                this.gridResponsables.getSelectionModel().clearSelection();
                JOptionPane.showMessageDialog(null, "El responsable fue insertado con éxito");
                this.volverConsultar();
            }//fin de if
            else{
                JOptionPane.showMessageDialog(null, UtilidadesCapaNegocios.getErrorOperacion(UtilidadesCapaNegocios.moduloResponsables, UtilidadesCapaNegocios.opInsertar), "ERROR", JOptionPane.ERROR_MESSAGE);
            }//fin de else
        }else{
            JOptionPane.showMessageDialog(null, "La persona con cédula " + responsable.getCedula() + " ya existe", "ERROR", JOptionPane.ERROR_MESSAGE);
        }

    }//fin de insertarResponsable

    private void modificarResponsable(){
        Responsable responsable = this.obtenerDatosResponsable();
        int resultado = this.controladoraResponsable.modificarResponsable(responsable);
        if(resultado == UtilidadesCapaNegocios.QUERY_OK){
            this.gridResponsables.getSelectionModel().clearSelection();
            JOptionPane.showMessageDialog(null, "El responsable fue modificado con éxito");
            this.volverConsultar();
        }//fin de if
        else{
            JOptionPane.showMessageDialog(null, UtilidadesCapaNegocios.getErrorOperacion(UtilidadesCapaNegocios.moduloResponsables, UtilidadesCapaNegocios.opModificar), "ERROR", JOptionPane.ERROR_MESSAGE);
        }//fin de else

    }//fin de modificarResponsable

    private void eliminarResponsable(){
        String cedula = this.txtCedula.getText();
        int resultado = this.controladoraResponsable.eliminarResponsable(cedula);
        if(resultado == UtilidadesCapaNegocios.QUERY_OK){
            this.gridResponsables.getSelectionModel().clearSelection();
            JOptionPane.showMessageDialog(null, "El responsable fue eliminado con éxito");
            this.volverConsultar();
        }//fin de if
        else{
            JOptionPane.showMessageDialog(null, UtilidadesCapaNegocios.getErrorOperacion(UtilidadesCapaNegocios.moduloResponsables, UtilidadesCapaNegocios.opEliminar), "ERROR", JOptionPane.ERROR_MESSAGE);
        }//fin de else

    }//fin de modificarResponsable

    private void consultarResponsable(String cedula){
        Responsable responsable = controladoraResponsable.consultarResponsable(cedula);
        if(responsable != null){
            this.llenarCamposResponsable(responsable);
        }else{
            String mensaje = UtilidadesCapaNegocios.getErrorOperacion(UtilidadesCapaNegocios.moduloResponsables, UtilidadesCapaNegocios.opConsultar);
            JOptionPane.showMessageDialog(null, mensaje, "ERROR",JOptionPane.ERROR_MESSAGE);
        }
    }//fin de consultarResponsable

    private void llenarCamposResponsable(Responsable responsable){
        this.txtNombre.setText(responsable.getNombre());
        this.txtApellidos.setText(responsable.getApellidos());
        this.txtCedula.setText(responsable.getCedula());
        Date fecha = responsable.getFechaNac();
        Calendar calendario = Calendar.getInstance();
        calendario.clear();
        calendario.setTime(fecha);
        this.spinDia.getModel().setValue(calendario.get(Calendar.DAY_OF_MONTH));
        this.spinMes.getModel().setValue(calendario.get(Calendar.MONTH) + 1);
        this.spinAño.getModel().setValue(calendario.get(Calendar.YEAR));
        this.cbSexo.setSelectedItem(UtilidadesCapaNegocios.obtenerSexo(responsable.getSexo()));
        this.txtNacionalidad.setText(responsable.getNacionalidad());
        this.txtTelefono1.setText(responsable.getTelefono1());
        this.txtTelefono2.setText(responsable.getTelefono2());
        this.txtProvincia.setText(responsable.getProvincia());
        this.txtCanton.setText(responsable.getCanton());
        this.txtDistrito.setText(responsable.getDistrito());
        this.txtOtrasSeñas.setText(responsable.getOtrasSenias());
        this.habilitarBotonesIME(permisoResponsable.isInsertar(), permisoResponsable.isModificar(), permisoResponsable.isEliminar());
    }

    private void volverConsultar(){
        this.limpiarCampos();
        this.estado.setEstadoActual(Estado.CONSULTAR);
        this.habilitarBotonesIME(permisoResponsable.isInsertar(), permisoResponsable.isModificar(), permisoResponsable.isEliminar());
        this.setHabilitarCampos(false);
        this.cbCedula.setEnabled(true);
        this.cbNombreApellidos.setEnabled(true);
        this.habilitarAceptarCancelar(false);
        String cedulaEstudiante = this.cbCedula.getSelectedItem().toString();
        this.cargarComboBoxDatosEstudiante();
        this.cbCedula.setSelectedItem(cedulaEstudiante);
        this.cargarGridResponsables();
    }//fin de volverConsultar


    private void cargarGridResponsables(){
        this.habilitarBotonesIME(permisoResponsable.isInsertar(), false, false);
        this.limpiarGridResponsables();
        String cedulaEstudiante = cbCedula.getSelectedItem().toString();
        if(!cedulaEstudiante.trim().isEmpty()){
            LinkedList<Responsable> Responsables = controladoraResponsable.consultarResponsables(cedulaEstudiante);
            Iterator<Responsable> iterador = Responsables.iterator();
            while(iterador.hasNext()){
                Responsable personal = iterador.next();
                Object arregloDatos[] = new Object[3];
                arregloDatos[0] = personal.getCedula();
                arregloDatos[1] = personal.getNombre();
                arregloDatos[2] = personal.getApellidos();
                ((DefaultTableModel)this.gridResponsables.getModel()).addRow(arregloDatos);
            }
        }
    }//fin de cargarGridResponsables
    private void limpiarGridResponsables(){
        ((DefaultTableModel)this.gridResponsables.getModel()).setRowCount(0);
    }//fin de limpiarGridResponsables

    public void valueChanged(ListSelectionEvent evento){
        int filas = ((DefaultTableModel)this.gridResponsables.getModel()).getRowCount();
        if(filas > 0 && estado.getEstadoActual() == Estado.CONSULTAR){
            int fila = this.gridResponsables.getSelectedRow();
            if(fila >= 0){
                String cedula = this.gridResponsables.getModel().getValueAt(fila, 0).toString();
                this.consultarResponsable(cedula);
            }
        }//fin de if
    }//fin de método valueChanged

    private boolean validarDatos(){
        boolean resultado = true;
        resultado &= !txtCedula.getText().replaceAll("-", "").replaceAll("0", "").isEmpty();
        int dia = Integer.parseInt(this.spinDia.getValue().toString());
        int mes = Integer.parseInt(this.spinMes.getValue().toString())-1;
        int año = Integer.parseInt(this.spinAño.getValue().toString());
        Calendar calendario = Calendar.getInstance();
        calendario.clear();
        calendario.set(año,mes,dia);
        resultado &= (calendario.get(Calendar.DAY_OF_MONTH) == dia) && (calendario.get(Calendar.MONTH) == mes) && (calendario.get(Calendar.YEAR) == año);
        if(!resultado){
            JOptionPane.showMessageDialog(null, "1.El número de cédula debe ser válido.\n2.Debe digitar una fecha válida", "ERROR",JOptionPane.WARNING_MESSAGE);
        }
        return resultado;
    }//fin de validarDatos

    private boolean verificarDatosObligatorios(){
        boolean resultado = true;
        resultado &= !txtNombre.getText().trim().isEmpty();
        resultado &= !txtApellidos.getText().trim().isEmpty();
        resultado &= !txtCedula.getText().replaceAll("-", "").trim().isEmpty();
        resultado &= !txtTelefono1.getText().trim().isEmpty();
        resultado &= !cbCedula.getSelectedItem().toString().trim().isEmpty();
        if(!resultado){
            JOptionPane.showMessageDialog(null, "Los campos nombre, apellidos, número de cédula,\n"+
                    "teléfono #1 y el estudiante son obligatorios", "ERROR",JOptionPane.WARNING_MESSAGE);
        }
        return resultado;
    }//fin de verificarDatosObligatorios


    @Action
    public void insertandoResponsable() {
        this.estado.setEstadoActual(Estado.INSERTAR);
        this.limpiarCampos();
        this.setHabilitarCampos(true);
        this.habilitarBotonesIME(false, false, false);
        this.habilitarAceptarCancelar(true);
    }//fin de insertandoResponsable

    @Action
    public void modificandoResponsable() {
        this.estado.setEstadoActual(Estado.MODIFICAR);
        this.cbCedula.setEnabled(false);
        this.cbNombreApellidos.setEnabled(false);
        this.setHabilitarCampos(true);
        this.habilitarBotonesIME(false, false, false);
        this.habilitarAceptarCancelar(true);
        this.txtCedula.setEditable(false);
    }//fin de insertandoResponsable

    @Action
    public void eliminandoResponsable() {
        Animador.animar();
        if(this.mostrarMensajeConfirmacion(UtilidadesCapaNegocios.opEliminar, "ELIMINAR")){
            this.eliminarResponsable();
        }
        Animador.detenerAnimacion();
    }//fin de insertandoResponsable
    /**
     ** Muestra un mensaje de confirmación para que el usuario decida si realmente
     ** quiere llevar a cabo una operación
     ** @param operacion Código de operación realizada, tomada de UtilidadesCapaNegocios
     ** @param titulo Título a mostrar en el cuadro de confirmación
     ** @return Confirmación: true si el usuario acepta, false en otro caso.
     **/
    private boolean mostrarMensajeConfirmacion(int operacion,String titulo){
        boolean resultado = true;
        String mensaje = UtilidadesCapaNegocios.getMensajeConfirmacion(UtilidadesCapaNegocios.moduloResponsables, operacion);
        int respuesta = JOptionPane.showConfirmDialog(null, mensaje,titulo ,JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
        resultado = respuesta == JOptionPane.OK_OPTION;
        return resultado;
    }//fin de mostrarMensajeConfirmacion

    @Action
    public void accionAceptar() {
        Animador.animar();
        switch(estado.getEstadoActual()){
            case Estado.INSERTAR:
                if(mostrarMensajeConfirmacion(UtilidadesCapaNegocios.opInsertar, "INSERTAR") ){
                    if(verificarDatosObligatorios() && validarDatos()){
                        this.insertarResponsable();
                    }
                }
            break;
            case Estado.MODIFICAR:
                if(mostrarMensajeConfirmacion(UtilidadesCapaNegocios.opModificar, "MODIFICAR") ){
                    if(verificarDatosObligatorios() && validarDatos()){
                        this.modificarResponsable();
                    }
                }
            break;
        }
        Animador.detenerAnimacion();
    }//fin de accionAceptar

    @Action
    public void accionCancelar() {
        this.limpiarCampos();
        this.volverConsultar();
    }//fin de accionCancelar


    private void cargarComboBoxDatosEstudiante(){
        ControladoraEstudiante contEstudiante = new ControladoraEstudiante();
        LinkedList<Estudiante> listaEstudiantes = contEstudiante.consultarEstudiantes();
        DefaultComboBoxModel modeloCedula = new DefaultComboBoxModel();
        DefaultComboBoxModel modeloNombreApellidos = new DefaultComboBoxModel();
        modeloCedula.addElement("");
        modeloNombreApellidos.addElement("");
        Iterator<Estudiante> iterador = listaEstudiantes.iterator();
        while(iterador.hasNext()){
            Estudiante estudiante = iterador.next();
            modeloCedula.addElement(estudiante.getCedula());
            modeloNombreApellidos.addElement(estudiante.getNombre() + " " + estudiante.getApellidos());
        }//fin de while
        this.cbCedula.setModel(modeloCedula);
        this.cbNombreApellidos.setModel(modeloNombreApellidos);
    }//fin de cargarComboBoxDatosEstudiante
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbNombre = new javax.swing.JLabel();
        lbApellidos = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApellidos = new javax.swing.JTextField();
        lbCedula = new javax.swing.JLabel();
        lbFechaNacimiento = new javax.swing.JLabel();
        lbSeparador1 = new javax.swing.JLabel();
        lbSeparador2 = new javax.swing.JLabel();
        lbSexo = new javax.swing.JLabel();
        cbSexo = new javax.swing.JComboBox();
        lbTelefono1 = new javax.swing.JLabel();
        lbTelefono2 = new javax.swing.JLabel();
        lbNacionalidad = new javax.swing.JLabel();
        txtNacionalidad = new javax.swing.JTextField();
        lbProvincia = new javax.swing.JLabel();
        txtProvincia = new javax.swing.JTextField();
        lbCanton = new javax.swing.JLabel();
        txtCanton = new javax.swing.JTextField();
        lbDistrito = new javax.swing.JLabel();
        txtDistrito = new javax.swing.JTextField();
        lbOtrasSenas = new javax.swing.JLabel();
        btnInsertar = new javax.swing.JButton();
        btnModificar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        scrollTablaEstudiantes = new javax.swing.JScrollPane();
        gridResponsables = new javax.swing.JTable();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        txtCedula = new javax.swing.JFormattedTextField(createFormatter("#-####-####"));
        txtTelefono1 = new javax.swing.JFormattedTextField(createFormatter("##-##-##-##"));
        txtTelefono2 = new javax.swing.JFormattedTextField(createFormatter("##-##-##-##"));
        jLabel1 = new javax.swing.JLabel();
        cbCedula = new javax.swing.JComboBox();
        cbNombreApellidos = new javax.swing.JComboBox();
        spinDia = new javax.swing.JSpinner(new SpinnerNumberModel(1,1,31,1));
        spinMes = new javax.swing.JSpinner(new SpinnerNumberModel(1,1,12,1));
        spinAño = new javax.swing.JSpinner(new SpinnerNumberModel(1950,1900,2999,1));
        jScrollPane1 = new javax.swing.JScrollPane();
        txtOtrasSeñas = new javax.swing.JTextArea();
        obli1 = new javax.swing.JLabel();
        obli2 = new javax.swing.JLabel();
        obli3 = new javax.swing.JLabel();
        obli4 = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(665, 520));
        setMinimumSize(new java.awt.Dimension(665, 520));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(665, 520));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(adsec.presentacion.LiceoEscazuApp.class).getContext().getResourceMap(PanelResponsables.class);
        lbNombre.setText(resourceMap.getString("lbNombre.text")); // NOI18N
        lbNombre.setName("lbNombre"); // NOI18N

        lbApellidos.setText(resourceMap.getString("lbApellidos.text")); // NOI18N
        lbApellidos.setName("lbApellidos"); // NOI18N

        txtNombre.setText(resourceMap.getString("txtNombre.text")); // NOI18N
        txtNombre.setAutoscrolls(false);
        txtNombre.setName("txtNombre"); // NOI18N

        txtApellidos.setText(resourceMap.getString("txtApellidos.text")); // NOI18N
        txtApellidos.setAutoscrolls(false);
        txtApellidos.setName("txtApellidos"); // NOI18N

        lbCedula.setText(resourceMap.getString("lbCedula.text")); // NOI18N
        lbCedula.setName("lbCedula"); // NOI18N

        lbFechaNacimiento.setText(resourceMap.getString("lbFechaNacimiento.text")); // NOI18N
        lbFechaNacimiento.setName("lbFechaNacimiento"); // NOI18N

        lbSeparador1.setText(resourceMap.getString("lbSeparador1.text")); // NOI18N
        lbSeparador1.setName("lbSeparador1"); // NOI18N

        lbSeparador2.setText(resourceMap.getString("lbSeparador2.text")); // NOI18N
        lbSeparador2.setName("lbSeparador2"); // NOI18N

        lbSexo.setText(resourceMap.getString("lbSexo.text")); // NOI18N
        lbSexo.setName("lbSexo"); // NOI18N

        cbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Femenino", "Masculino" }));
        cbSexo.setName("cbSexo"); // NOI18N

        lbTelefono1.setText(resourceMap.getString("lbTelefono1.text")); // NOI18N
        lbTelefono1.setName("lbTelefono1"); // NOI18N

        lbTelefono2.setText(resourceMap.getString("lbTelefono2.text")); // NOI18N
        lbTelefono2.setName("lbTelefono2"); // NOI18N

        lbNacionalidad.setText(resourceMap.getString("lbNacionalidad.text")); // NOI18N
        lbNacionalidad.setName("lbNacionalidad"); // NOI18N

        txtNacionalidad.setText(resourceMap.getString("txtNacionalidad.text")); // NOI18N
        txtNacionalidad.setAutoscrolls(false);
        txtNacionalidad.setName("txtNacionalidad"); // NOI18N

        lbProvincia.setText(resourceMap.getString("lbProvincia.text")); // NOI18N
        lbProvincia.setName("lbProvincia"); // NOI18N

        txtProvincia.setText(resourceMap.getString("txtProvincia.text")); // NOI18N
        txtProvincia.setAutoscrolls(false);
        txtProvincia.setName("txtProvincia"); // NOI18N

        lbCanton.setText(resourceMap.getString("lbCanton.text")); // NOI18N
        lbCanton.setName("lbCanton"); // NOI18N

        txtCanton.setText(resourceMap.getString("txtCanton.text")); // NOI18N
        txtCanton.setAutoscrolls(false);
        txtCanton.setName("txtCanton"); // NOI18N

        lbDistrito.setText(resourceMap.getString("lbDistrito.text")); // NOI18N
        lbDistrito.setName("lbDistrito"); // NOI18N

        txtDistrito.setText(resourceMap.getString("txtDistrito.text")); // NOI18N
        txtDistrito.setAutoscrolls(false);
        txtDistrito.setName("txtDistrito"); // NOI18N

        lbOtrasSenas.setText(resourceMap.getString("lbOtrasSenas.text")); // NOI18N
        lbOtrasSenas.setName("lbOtrasSenas"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(adsec.presentacion.LiceoEscazuApp.class).getContext().getActionMap(PanelResponsables.class, this);
        btnInsertar.setAction(actionMap.get("insertandoResponsable")); // NOI18N
        btnInsertar.setText(resourceMap.getString("btnInsertar.text")); // NOI18N
        btnInsertar.setName("btnInsertar"); // NOI18N

        btnModificar.setAction(actionMap.get("modificandoResponsable")); // NOI18N
        btnModificar.setText(resourceMap.getString("btnModificar.text")); // NOI18N
        btnModificar.setName("btnModificar"); // NOI18N

        btnEliminar.setAction(actionMap.get("eliminandoResponsable")); // NOI18N
        btnEliminar.setText(resourceMap.getString("btnEliminar.text")); // NOI18N
        btnEliminar.setName("btnEliminar"); // NOI18N

        scrollTablaEstudiantes.setName("scrollTablaEstudiantes"); // NOI18N

        gridResponsables.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cédula", "Nombre", "Apellidos"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gridResponsables.setName("tablaEstudiantes"); // NOI18N
        scrollTablaEstudiantes.setViewportView(gridResponsables);
        gridResponsables.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        gridResponsables.getSelectionModel().addListSelectionListener(this);

        btnAceptar.setAction(actionMap.get("accionAceptar")); // NOI18N
        btnAceptar.setText(resourceMap.getString("btnAceptar.text")); // NOI18N
        btnAceptar.setName("btnAceptar"); // NOI18N

        btnCancelar.setAction(actionMap.get("accionCancelar")); // NOI18N
        btnCancelar.setText(resourceMap.getString("btnCancelar.text")); // NOI18N
        btnCancelar.setName("btnCancelar"); // NOI18N

        txtCedula.setText(resourceMap.getString("txtCedula.text")); // NOI18N
        txtCedula.setName("txtCedula"); // NOI18N

        txtTelefono1.setText(resourceMap.getString("txtTelefono1.text")); // NOI18N
        txtTelefono1.setName("txtTelefono1"); // NOI18N

        txtTelefono2.setText(resourceMap.getString("txtTelefono2.text")); // NOI18N
        txtTelefono2.setName("txtTelefono2"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        cbCedula.setName("cbCedula"); // NOI18N

        cbNombreApellidos.setName("cbNombreApellidos"); // NOI18N

        spinDia.setName("spinDia"); // NOI18N

        spinMes.setName("spinMes"); // NOI18N

        spinAño.setName("spinAño"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtOtrasSeñas.setColumns(20);
        txtOtrasSeñas.setRows(5);
        txtOtrasSeñas.setName("txtOtrasSeñas"); // NOI18N
        jScrollPane1.setViewportView(txtOtrasSeñas);

        obli1.setForeground(resourceMap.getColor("obli1.foreground")); // NOI18N
        obli1.setText(resourceMap.getString("obli1.text")); // NOI18N
        obli1.setName("obli1"); // NOI18N

        obli2.setForeground(resourceMap.getColor("obli2.foreground")); // NOI18N
        obli2.setText(resourceMap.getString("obli2.text")); // NOI18N
        obli2.setName("obli2"); // NOI18N

        obli3.setForeground(resourceMap.getColor("obli3.foreground")); // NOI18N
        obli3.setText(resourceMap.getString("obli3.text")); // NOI18N
        obli3.setName("obli3"); // NOI18N

        obli4.setForeground(resourceMap.getColor("obli4.foreground")); // NOI18N
        obli4.setText(resourceMap.getString("obli4.text")); // NOI18N
        obli4.setName("obli4"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnInsertar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnModificar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminar)
                        .addGap(10, 10, 10))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnAceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar)
                        .addGap(10, 10, 10))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(scrollTablaEstudiantes, javax.swing.GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel1)
                                    .addComponent(lbFechaNacimiento)
                                    .addComponent(lbSexo)
                                    .addComponent(lbNacionalidad)
                                    .addComponent(lbTelefono1)
                                    .addComponent(lbProvincia)
                                    .addComponent(lbOtrasSenas)
                                    .addComponent(lbCedula)
                                    .addComponent(lbApellidos)
                                    .addComponent(lbNombre))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtTelefono1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(10, 10, 10)
                                        .addComponent(lbTelefono2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtTelefono2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(10, 10, 10)
                                        .addComponent(lbCanton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtCanton, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lbDistrito)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(obli3))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(obli2))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(cbCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbNombreApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(obli1))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(spinDia, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(lbSeparador1)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(spinMes, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(lbSeparador2))
                                            .addComponent(txtCedula, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(obli4)
                                            .addComponent(spinAño, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE))))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnInsertar)
                            .addComponent(btnModificar)
                            .addComponent(btnEliminar))
                        .addGap(60, 60, 60))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel1)
                            .addComponent(cbCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbNombreApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(obli1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbNombre)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(obli2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbApellidos)
                    .addComponent(txtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(obli3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbCedula)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(obli4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbFechaNacimiento)
                    .addComponent(spinDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbSeparador1)
                    .addComponent(spinMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbSeparador2)
                    .addComponent(spinAño, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbSexo))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbNacionalidad)
                    .addComponent(txtNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbTelefono2)
                    .addComponent(lbTelefono1)
                    .addComponent(txtTelefono1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTelefono2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(lbDistrito)
                    .addComponent(txtDistrito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCanton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbCanton)
                    .addComponent(txtProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbProvincia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbOtrasSenas))
                .addGap(9, 9, 9)
                .addComponent(scrollTablaEstudiantes, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAceptar)
                    .addComponent(btnCancelar))
                .addGap(7, 7, 7))
        );

        this.cbCedula.addItemListener(this);
        this.cbNombreApellidos.addItemListener(this);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnInsertar;
    private javax.swing.JButton btnModificar;
    private javax.swing.JComboBox cbCedula;
    private javax.swing.JComboBox cbNombreApellidos;
    private javax.swing.JComboBox cbSexo;
    private javax.swing.JTable gridResponsables;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbApellidos;
    private javax.swing.JLabel lbCanton;
    private javax.swing.JLabel lbCedula;
    private javax.swing.JLabel lbDistrito;
    private javax.swing.JLabel lbFechaNacimiento;
    private javax.swing.JLabel lbNacionalidad;
    private javax.swing.JLabel lbNombre;
    private javax.swing.JLabel lbOtrasSenas;
    private javax.swing.JLabel lbProvincia;
    private javax.swing.JLabel lbSeparador1;
    private javax.swing.JLabel lbSeparador2;
    private javax.swing.JLabel lbSexo;
    private javax.swing.JLabel lbTelefono1;
    private javax.swing.JLabel lbTelefono2;
    private javax.swing.JLabel obli1;
    private javax.swing.JLabel obli2;
    private javax.swing.JLabel obli3;
    private javax.swing.JLabel obli4;
    private javax.swing.JScrollPane scrollTablaEstudiantes;
    private javax.swing.JSpinner spinAño;
    private javax.swing.JSpinner spinDia;
    private javax.swing.JSpinner spinMes;
    private javax.swing.JTextField txtApellidos;
    private javax.swing.JTextField txtCanton;
    private javax.swing.JFormattedTextField txtCedula;
    private javax.swing.JTextField txtDistrito;
    private javax.swing.JTextField txtNacionalidad;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextArea txtOtrasSeñas;
    private javax.swing.JTextField txtProvincia;
    private javax.swing.JFormattedTextField txtTelefono1;
    private javax.swing.JFormattedTextField txtTelefono2;
    // End of variables declaration//GEN-END:variables

}
